<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

</head>
<body>

<input type="button" value="查询所有" id="btn1"/>
<input type="button" value="查询一个" id="btn2"/>
<input type="button" value="增加部门" id="btn3"/>
<input type="button" value="修改部门" id="btn4"/>
<input type="button" value="删除部门" id="btn5"/>
<input type="button" value="批量删除部门" id="btn6"/>
<script type="text/javascript"  src="${pageContext.request.contextPath}/js/jquery-1.12.3.min.js"></script>

<script type="text/javascript">

  $("#btn1").click(function(){
	  $.ajax({
	    	url:"${pageContext.request.contextPath}/depts",
	    	type:"get",
	    	async:true,
	        dataType:"json",
	    	error:function(){
	    		
	    	},
	    	success:function(datas){
	    		
	    		alert(datas.data);
	    	}
	    	
	    	
	    	
	    })
	  
	  
  });
  
  
  $("#btn2").click(function(){
	  $.ajax({
	    	url:"${pageContext.request.contextPath}/depts/1",
	    	type:"get",
	    	async:true,
	        dataType:"json",
	    	error:function(){
	    		
	    	},
	    	success:function(datas){
	    		
	    		alert(datas);
	    	}
	    	
	    	
	    	
	    })
	  
	  
  });
  
  $("#btn3").click(function(){
	  $.ajax({
	    	url:"${pageContext.request.contextPath}/depts",
	    	type:"post",
	    	async:true,
	       //dataType:"json",
	        data:{"dcode":"d009","dname":"测试"},
	    	error:function(){
	    		
	    	},
	    	success:function(datas){
	    		
	    		alert(datas);
	    	}
	    	
	    	
	    	
	    })
	  
	  
  });
  
  
  $("#btn4").click(function(){
	  $.ajax({
	    	url:"${pageContext.request.contextPath}/depts",
	    	type:"post",
	    	async:true,
	       //dataType:"json",
	        data:{"id":1,"dcode":"d009","dname":"测试","_method":"put"},
	    	error:function(){
	    		
	    	},
	    	success:function(datas){
	    		
	    		alert(datas);
	    	}
	    	
	    	
	    	
	    })
	  
	  
  });
   
  $("#btn5").click(function(){
	  $.ajax({
	    	url:"${pageContext.request.contextPath}/depts",
	    	type:"post",
	    	async:true,
	       //dataType:"json",
	         data:{"id":7,"_method":"delete"} ,
	    	error:function(){
	    		
	    	},
	    	success:function(datas){
	    		
	    		alert(datas);
	    	}
	    	
	    	
	    	
	    })
	  
	  
  });
</script>
</body>
</html>